#include <stdio.h>
#include <windows.h>
//#include <dlfcn.h>
typedef int (*AddNumbersFunc)(int, int);

int main() {
    // 加载动态库
    void *handle = LoadLibrary("../libaddnumbers.dll");
    //void *handle = dlopen("libaddnumbers.so", RTLD_LAZY);
    if (!handle) {
        printf("Error loading library\n");
        return 1;
    }

    // 获取 AddNumbers 函数的地址
    AddNumbersFunc addNumbers = (AddNumbersFunc)GetProcAddress(handle, "AddNumbers");
    //AddNumbersFunc addNumbers = (AddNumbersFunc)dlsym(handle, "AddNumbers");
    if (!addNumbers) {
        printf("Error getting function address\n");
        FreeLibrary(handle);
        //dlclose(handle);
        return 1;
    }

    // 调用 AddNumbers 函数
    int result = addNumbers(5, 10);
    printf("The sum is: %d\n", result);

    // 关闭动态库
    FreeLibrary(handle);
    //dlclose(handle);
    return 0;
}